/*************************************************************************
 *                                                                       *
 * This file is part of the DogosFrame distribution.  For full copyright *
 * information, see COPYRIGHT and COPYING.LESSER.                        *
 *                                                                       *
 * Author:           sqbang                                              *
 * Email:            sqbang@ustc.edu                                     *
 *                                                                       *
 *************************************************************************/

#include "COMMON/tbox/CommandLineParser.h"

//C++ header
#include <iostream> //only for debug

namespace DOGOS
{

CommandLineParser::CommandLineParser(
    int argc,
    char **argv)
{
    for (int i = 0; i < argc; ++i)
    {
        std::string command (argv[i]);
        d_commands.push_back(command);
    }

    //the follow is test part
    /*
    for (unsigned int i=0;i<_commands.size();++i)
    {
        POUT<<_commands[i]<< " ";
    }
    POUT<<std::endl;
    */
}



bool
CommandLineParser::has_option (
    const std::string& option) const
{
    std::vector<std::string>::const_iterator pc=d_commands.begin();
    for (; pc!=d_commands.end(); ++pc)
    {
        if (*pc==option)
            return true;
    }
    return false;
}



std::string
CommandLineParser::get_parameter(
    const std::string& option) const
{
    std::string para;
    std::vector<std::string>::const_iterator pc=d_commands.begin();
    for (; pc!=d_commands.end(); ++pc)
    {
        if (*pc==option)
        {
            ++pc;
            if (pc!=d_commands.end())
            {
                para=*pc;
            }
            return para;
        }
    }

    return para;
}

}
